package com.joolun.mall.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.joolun.common.config.JooLunConfig;
import com.joolun.common.exception.CustomException;
import com.joolun.common.utils.EnvUtil;
import com.joolun.common.utils.FileUtil;
import com.joolun.common.utils.StringUtils;
import com.joolun.mall.domain.dto.ChainOrderDetailDTO;
import com.joolun.mall.domain.vo.ChainCheckOrderDetailVO;
import com.joolun.mall.domain.vo.ChainOrderDetailVO;
import com.joolun.mall.domain.vo.FileVO;
import com.joolun.mall.entity.*;
import com.joolun.mall.mapper.*;
import com.joolun.mall.service.IChainOrderDetailService;
import com.joolun.mall.service.IChainOrderService;
import com.joolun.mall.service.IChainPlanService;
import com.joolun.mall.service.IChainService;
import com.joolun.mall.util.excel.CustomRowHeightStyleStrategy;
import com.joolun.mall.util.excel.SingleRowHeightHandler;
import com.joolun.weixin.entity.WxUser;
import com.joolun.weixin.service.WxUserService;
import com.joolun.weixin.utils.ThirdSessionHolder;
import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.joolun.common.utils.StringUtils.trim;

/**
 * 品牌Service业务层处理
 *
 * @author www.joolun.com
 * @date 2025-05-20
 */
@Service
public class ChainOrderServiceImpl extends ServiceImpl<ChainOrderMapper, ChainOrder> implements IChainOrderService
{
    @Autowired
    private EnvUtil envUtil;

    @Autowired
    private ChainOrderDetailMapper orderDetailMapper;

    @Autowired
    private IChainOrderDetailService orderDetailService;

    @Autowired
    private ChainOrderMapper  orderMapper;

    @Autowired
    private IChainOrderService  orderServivce;

    @Autowired
    private ChainMapper chainMapper;

    @Autowired
    private ChainDetailMapper chainDetailMapper;

    @Autowired
    private IChainService chainService;

    @Autowired
    private IChainPlanService planService;

    @Autowired
    private WxUserService wxUserService;

    @Autowired
    private ChainTbWdtRelMapper chainTbWdtRelMapper;


    @Transactional
    @Override
    public Long add(ChainOrder order) {
        Long chainId = order.getChainId();
        Chain chain = checkChain(chainId);
        List<ChainOrderDetail> details = checkOrder(order, chain);
        order.setUserId(Long.valueOf(ThirdSessionHolder.getWxUserId()));
        WxUser wxUser = wxUserService.getById(ThirdSessionHolder.getWxUserId());
        order.setWxNickName(wxUser.getNickName());
        //重置订单状态为正常订单
        order.setStatus("0");
        if(CollectionUtil.isNotEmpty(details)){
            Set<String> skuCodes = new HashSet<>();
            details.forEach(orderDetail -> {
                if(skuCodes.contains(orderDetail.getSkuCode())){
                    throw new CustomException( orderDetail.getSpuName()+ "选择了相同的颜色尺码:");
                }

                skuCodes.add(orderDetail.getSkuCode());
            });
        }

        List<ChainOrder> dbOrders = orderMapper.selectList(Wrappers.<ChainOrder>lambdaQuery()
                .eq(ChainOrder::getChainId, chainId)
                .eq(ChainOrder::getUserId, ThirdSessionHolder.getWxUserId())
                .eq(ChainOrder::getDelFlag, "0")
        );

        //如果订单不存在直接新增
        if(CollectionUtil.isEmpty(dbOrders)){
            order.setCreateTime(new Date());
            order.setUpdateTime(new Date());
            List<ChainOrder> tbOrders = orderMapper.selectList(Wrappers.<ChainOrder>lambdaQuery()
                    .eq(ChainOrder::getChainId, chainId)
                    .eq(ChainOrder::getTbUserId, order.getTbUserId())
                    .eq(ChainOrder::getDelFlag, "0")
            );
            if(CollectionUtil.isNotEmpty(tbOrders)){
                throw new CustomException("该淘宝ID用户已经存在接龙，请勿重复提交");
            }
            orderServivce.save(order);
        }else{
            ChainOrder dbOrder = dbOrders.get(0);
            order.setId(dbOrder.getId());
            ChainOrderDetail chainOrderDetail = new ChainOrderDetail();
            chainOrderDetail.setDelFlag("2");
//            chainOrderDetail.setUpdateBy(SecurityUtils.getUsername());
            chainOrderDetail.setUpdateTime(new Date());
            orderDetailService.update(chainOrderDetail,
                    Wrappers.<ChainOrderDetail>lambdaQuery().eq(ChainOrderDetail::getChainOrderId, dbOrder.getId())
            );
            orderServivce.updateById(order);
        }

        if(CollectionUtil.isNotEmpty(details)){
            details.forEach(orderDetail -> {
                orderDetail.setCreateTime(new Date());
                orderDetail.setChainOrderId(order.getId());
            });
        }

        orderDetailService.saveBatch(details);
        int count = orderMapper.selectCount(
                Wrappers.<ChainOrder>lambdaQuery()
                        .in(ChainOrder::getChainId,order.getChainId())
                        .eq(ChainOrder::getDelFlag, "0")
        );
        //如果数量为0 并且不是修改订单信息
        if(order.getForceSubmit() == 0 && CollectionUtil.isEmpty(dbOrders)){
            if(Objects.nonNull(chain.getMaxChainNum()) && count > chain.getMaxChainNum()){
                throw new CustomException("当前接龙人数已超过" + chain.getMaxChainNum() +"，是否继续提交，继续提交如货品不足，无法保证优先发货",100001);
            }
        }


        //如果是新增接龙 设置是否超卖
        if(CollectionUtil.isEmpty(dbOrders)){
            order.setRank(count);
            order.setIsExceed(Objects.nonNull(chain.getMaxChainNum()) && count > chain.getMaxChainNum()? 1 : 0);
            orderServivce.updateById(order);
        }
        return order.getId();
    }

    @Override
    public String lastTbId(){
        List<ChainOrder> list = orderServivce.list(
                Wrappers.<ChainOrder>lambdaQuery()
                        .eq(ChainOrder::getUserId, ThirdSessionHolder.getWxUserId())
                        .eq(ChainOrder::getDelFlag, "0")
                        .orderByDesc(ChainOrder::getId)
                        .last("limit 1")
        );
        if(CollectionUtil.isEmpty(list)){
            return "";
        }else{
            return list.get(0).getTbUserId();
        }
    }


    private List<ChainOrderDetail> checkOrder(ChainOrder order, Chain chain) {
        if(Objects.isNull(order.getTbUserId())){
            throw new CustomException("淘宝旺旺id不能为空");
        }

        ChainPlan plan = planService.getById(chain.getPlanId());


        List<ChainTbWdtRel> chainTbWdtRels = chainTbWdtRelMapper.selectList(
                Wrappers.<ChainTbWdtRel>lambdaQuery()
                        .eq(ChainTbWdtRel::getTbUserId, order.getTbUserId())
                        .eq(ChainTbWdtRel::getBrandId, plan.getBrandId())
                        .eq(ChainTbWdtRel::getDelFlag, "0")
        );
        if(CollectionUtil.isEmpty(chainTbWdtRels)){
//            throw new CustomException("淘宝旺旺id不在VIP列表中");
            throw new CustomException("您填写的淘宝账号（旺旺ID）有误，请联系VIP小助理核对");
        }

        if(Objects.nonNull(chain.getMaxPickNum()) && order.getDetails().size() > chain.getMaxPickNum()){
            throw new CustomException("本次接龙仅允许选择"+  chain.getMaxPickNum() +"件商品，已选商品数量，超过接龙限制数量，请重新选择",100002);
        }
        List<ChainOrderDetail> details = order.getDetails();
        if(CollectionUtil.isEmpty(details)){
            throw new CustomException("接龙商品信息不能为空");
        }

        List<String> skuCodes = details.stream().map(ChainOrderDetail::getSkuCode).distinct().collect(Collectors.toList());
        List<ChainDetail> chainDetails = chainDetailMapper.selectList(Wrappers.<ChainDetail>lambdaQuery()
                .eq(ChainDetail::getChainId, chain.getId())
                .in(ChainDetail::getSkuCode, skuCodes)
                .eq(ChainDetail::getDelFlag, "0")
        );
        if(skuCodes.size() != chainDetails.size()){
            throw new CustomException("请勿提交不存在的货品");
        }
        return details;
    }


    private Chain checkChain(Long chainId) {
        if(Objects.isNull(chainId)){
            throw new CustomException("请选择接龙链接");
        }
        Chain chain = chainMapper.selectById(chainId);
        if(chain.getBeginDate().after(new Date())){
            throw new CustomException("接龙还未开始");
        }
        if(chain.getEndDate().before(new Date())){
            throw new CustomException("接龙已结束");
        }
        return chain;
    }


    @Override
    public ChainOrder chainOrder(Long chainId, String userId) {
        List<ChainOrder> chainOrders = orderMapper.selectList(
                Wrappers.<ChainOrder>query().lambda()
                        .in(ChainOrder::getUserId, userId)
                        .in(ChainOrder::getChainId, chainId)
                        .eq(ChainOrder::getDelFlag, "0")
        );
        if(CollectionUtil.isEmpty(chainOrders)){
            return null;
        }

        ChainOrder chainOrder = chainOrders.get(0);
        List<ChainOrderDetail> chainOrderDetails = orderDetailMapper.selectList(
                Wrappers.<ChainOrderDetail>lambdaQuery()
                        .in(ChainOrderDetail::getChainOrderId, chainOrder.getId())
                        .eq(ChainOrderDetail::getDelFlag, "0")
        );
        chainOrder.setDetails(chainOrderDetails);
        chainOrder.setRank(Objects.isNull(chainOrder.getRank())? 1 : chainOrder.getRank()); //排名如果是空给第一名
        return chainOrder;
    }

    @Override
    public List<ChainOrderDetailVO> selectOrderDetails(ChainOrderDetailDTO dto) {
        List<Chain> chains = dealExportParam(dto);
        if(CollectionUtil.isEmpty(dto.getChainIds())){
            return new ArrayList<>();
        }
        return orderDetailMapper.selectOrderDetails(dto);
    }

    private List<Chain> dealExportParam(ChainOrderDetailDTO dto) {
        if(CollectionUtil.isEmpty(dto.getChainIds()) && Objects.isNull(dto.getPlanId())){
            throw new CustomException("请选择链接或者计划");
        }
        List<Long> chainIds = new ArrayList<>();
        if(Objects.nonNull(dto.getPlanId())){
            List<Chain> chains = chainMapper.selectList(Wrappers.<Chain>query().lambda().in(Chain::getPlanId, dto.getPlanId()).eq(Chain::getDelFlag, "0"));
            chainIds = chains.stream().map(Chain::getId).collect(Collectors.toList());
            dto.setChainIds(chainIds);
            return chains;
        }
        return new ArrayList<>();

    }

    // 创建表头样式（可选）
    private static WriteCellStyle createHeaderStyle() {
        WriteCellStyle style = new WriteCellStyle();
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        style.setHorizontalAlignment(HorizontalAlignment.CENTER);
        return style;
    }

    // 创建内容样式（可选）
    private static WriteCellStyle createContentStyle() {
        WriteCellStyle style = new WriteCellStyle();
        style.setHorizontalAlignment(HorizontalAlignment.CENTER);
        return style;
    }

    @Override
    public FileVO selectCheckOrderDetails(ChainOrderDetailDTO dto) {
        dealExportParam(dto);
        if(CollectionUtil.isEmpty(dto.getChainIds())){
            throw new CustomException("无数据");
        }

        FileVO fileVO = new FileVO();

        String uploadPath = FileUtil.getUploadPath("111.xlsx");
        String fullFilePath = JooLunConfig.getDownloadPath() +uploadPath;
        FileUtil.createFileWithDir(fullFilePath);

        ExcelWriter excelWriter = EasyExcel.write(fullFilePath)
//                .registerWriteHandler(new SingleRowHeightHandler(1,100))
                .registerWriteHandler(getHeightAndFontStrategy())
//                .registerWriteHandler(new HorizontalCellStyleStrategy(createHeaderStyle(), createContentStyle()))
                .excelType(ExcelTypeEnum.XLSX).build();
        AtomicReference<List<List<String>>> dynamicHeaders = new AtomicReference<>();
        AtomicInteger chainCount = new AtomicInteger(0);

        dto.getChainIds().forEach(chainId -> {
            Chain chain = chainService.detail(chainId,false);
            if(Objects.nonNull(chain) && Objects.nonNull(chain.getDetails())){

                //根据下单名称分组
                Map<String, List<ChainDetail>> chainDetailGroup = chain.getDetails().stream()
                        .collect(
                                Collectors.groupingBy(
                                        ChainDetail::getSpuName,
                                        LinkedHashMap::new,
                                        Collectors.toList()
                                )
                        );
                List<String> headers = new ArrayList<>();
                chainDetailGroup.forEach((spuName_maxSpuNum, chainDetails) -> {
                    ChainDetail chainDetail = chainDetails.get(0);
                    for (int i = 1; i <= chainDetail.getMaxSpuNum(); i++) {
                        String suffix = "第"+toChineseUpper(i)+"件";
                        if(i==1) {
                            suffix="";
                        }
                        headers.add( suffix + chainDetail.getSpuName()+"颜色");
                        headers.add( suffix + chainDetail.getSpuName()+"尺码");
                    }
                });

                //动态表头
                dynamicHeaders.set(genHeader(chain, headers));
                ChainOrderDetailDTO newDTO = new ChainOrderDetailDTO();
                newDTO.setChainIds(Collections.singletonList(chainId));
                List<ChainCheckOrderDetailVO> orderDetails = orderDetailMapper.selectCheckOrderDetails(dto);




                //接龙用户分组明细 需要排序 先分组的放前面
                Map<Long, List<ChainCheckOrderDetailVO>> userOrderGroups = orderDetails.stream().filter(e -> e.getChainId().equals(chainId))
                        .collect(Collectors.groupingBy(
                                ChainCheckOrderDetailVO::getUserId,
                                LinkedHashMap::new,
                                Collectors.toList()
                        ));
                //动态数据
                List<List<String>> dynamicDatas = new ArrayList<>();
                AtomicInteger jielongNo = new AtomicInteger(0);
                userOrderGroups.forEach( (userId, orderDetailVOS) -> {
                    //给它先排序
                    orderDetailVOS = orderDetailVOS.stream().sorted(Comparator.comparing(ChainCheckOrderDetailVO::getId)).collect(Collectors.toList());

                    //判断是否是用户基本信息 如果为0 为基本信息 初始化循环一次
                    AtomicInteger row = new AtomicInteger(0);
                    //用户分完组后 再根据链接分组 需要排序 先分组的放前面
                    Map<String, List<ChainCheckOrderDetailVO>> userOrderDetailGroup = orderDetailVOS.stream()
                            .filter(e -> e.getChainId().equals(chainId))
                            .collect(Collectors.groupingBy(ChainCheckOrderDetailVO::getSpuName,
                                    LinkedHashMap::new,
                                    Collectors.toList()
                            ));
                    List<String> dynamicData = new ArrayList<>();
                    List<ChainCheckOrderDetailVO> chainCheckOrderDetailVOS = userOrderGroups.get(userId);
                    if (CollectionUtil.isNotEmpty(chainCheckOrderDetailVOS)) {
                        ChainCheckOrderDetailVO orderDetailVO = chainCheckOrderDetailVOS.get(0);
                        dynamicData.add(orderDetailVO.getRank()+"");
                        dynamicData.add(trim(orderDetailVO.getWxNickName()));
                        dynamicData.add(StringUtils.maskStr(trim(orderDetailVO.getTbUserId())));
                    }
                    chainDetailGroup.forEach((spuName, chainDetails) -> {
                        ChainDetail chainDetail = chainDetails.get(0);
                        for (int i = 1; i <= chainDetail.getMaxSpuNum(); i++) {
                            List<ChainCheckOrderDetailVO> userOrderDetails = userOrderDetailGroup.get(spuName);

                            dynamicData.add((CollectionUtil.isNotEmpty(userOrderDetails) && userOrderDetails.size() >= i)? trim(userOrderDetails.get(i - 1).getColor()) : "不需要" );
                            dynamicData.add((CollectionUtil.isNotEmpty(userOrderDetails) && userOrderDetails.size() >= i)? trim(userOrderDetails.get(i - 1).getSize()) : "不需要" );
                        }
                    });
                    //如果取到的是最后一个数据
                    if (CollectionUtil.isNotEmpty(chainCheckOrderDetailVOS)) {
                        ChainCheckOrderDetailVO orderDetailVO = chainCheckOrderDetailVOS.get(0);
                        dynamicData.add(Objects.nonNull(orderDetailVO.getIsExceed()) && orderDetailVO.getIsExceed() == 1  ? "是" : "否");
                        dynamicData.add(trim(orderDetailVO.getTbUserId()));
                        dynamicData.add(trim(orderDetailVO.getWdtEncodeUserId()));
                        dynamicData.add(orderDetailVO.getSkuCode());
                        dynamicData.add(orderDetailVO.getVipTypeValue());
                    }
                    dynamicDatas.add(dynamicData);
                });

                fileVO.setFileName("【" + sanitizeFileName(chain.getName()) + "】" + "核对名单.xlsx");

                WriteSheet writeSheet = EasyExcel.writerSheet(chainCount.get(), sanitizeSheetName(chain.getName()))
                        .head(dynamicHeaders.get()) // 设置表头模型
                        .build();

                excelWriter.write(dynamicDatas, writeSheet);

                // 5. 获取Sheet并调整格式
                Sheet sheet = excelWriter.writeContext().writeSheetHolder().getSheet();

                // 设置第2行行高（单位：磅）
                Row headerRow = sheet.getRow(1);
                if (headerRow != null) {
                    headerRow.setHeightInPoints(90); // 设置行高为40磅
                }

                // 设置列宽（单位：1/256字符宽度）
                sheet.setColumnWidth(0, 20 * 150); // 第1列宽度100字符

                // 6. 插入图片（示例：第一行第一列）
                insertImageFromUrl(sheet, getHeadPicUrl(chain.getPics()), 1, 0);

                chainCount.getAndIncrement();
            }
        });
        excelWriter.finish();
        if(Objects.nonNull(dto.getPlanId())){
            ChainPlan plan = planService.getById(dto.getPlanId());
            fileVO.setFileName("【" + sanitizeFileName(plan.getName()) + "】" + "核对名单.xlsx");
        }
        fileVO.setUrl("/download/"+uploadPath);
        return fileVO;
    }

    public static String toChineseUpper(int number) {
        if (number < 1 || number > 10) {
            return "超出范围（仅支持1-10）";
        }

        String[] upperChineseNumbers = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"};
        return upperChineseNumbers[number - 1];
    }

    // 替换文件名中的非法字符（Windows系统规则）
    public static String sanitizeFileName(String fileName) {
        if (fileName == null || fileName.isEmpty()) {
            return fileName;
        }
        // 匹配Windows文件名非法字符: \ / : * ? " < > |
        Pattern illegalFileNameChars = Pattern.compile("[\\\\/:*?\"<>|]");
        return illegalFileNameChars.matcher(fileName).replaceAll("");
    }

    // 替换Excel工作表名称中的非法字符
    public static String sanitizeSheetName(String sheetName) {
        if (sheetName == null || sheetName.isEmpty()) {
            return sheetName;
        }
        // 匹配Excel工作表非法字符: \ / ? * [ ] :
        Pattern illegalSheetChars = Pattern.compile("[\\\\/?*\\[\\]:]");
        return illegalSheetChars.matcher(sheetName).replaceAll("");
    }


    private HorizontalCellStyleStrategy getHeightAndFontStrategy() {
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontHeightInPoints((short) 11);
        headWriteFont.setBold(true);
        headWriteCellStyle.setWriteFont(headWriteFont);
        headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
//        headWriteCellStyle.setFillBackgroundColor(IndexedColors.LIGHT_BLUE.getIndex());
        headWriteCellStyle.setShrinkToFit(true);

        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        WriteFont contentWriteFont = new WriteFont();
        contentWriteFont.setFontHeightInPoints((short) 11);
        contentWriteCellStyle.setWriteFont(contentWriteFont);
        //设置边框
        contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
        contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
        contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
        contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
        contentWriteCellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex()); // 设置左边框颜色为黑色
        contentWriteCellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex()); // 设置右边框颜色为黑色
        contentWriteCellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex()); // 设置上边框颜色为黑色
        contentWriteCellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex()); // 设置下边框颜色为黑色
        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
    }
    // 插入图片方法
    private void insertImageFromUrl(Sheet sheet, String imageUrl, int rowIdx, int colIdx) {
        try (InputStream is = new URL(imageUrl).openStream()) {
            // 1. 读取图片字节
            byte[] bytes = IOUtils.toByteArray(is);

            // 2. 添加图片到工作簿
            int pictureIdx = sheet.getWorkbook().addPicture(bytes, Workbook.PICTURE_TYPE_PNG);

            // 3. 创建绘图对象
            Drawing<?> drawing = sheet.createDrawingPatriarch();

            // 4. 计算图片位置
            CreationHelper helper = sheet.getWorkbook().getCreationHelper();
            ClientAnchor anchor = helper.createClientAnchor();
            anchor.setCol1(colIdx);      // 起始列
            anchor.setRow1(rowIdx);      // 起始行
            anchor.setCol2(colIdx + 1);  // 结束列（+1表示占1列宽度）
            anchor.setRow2(rowIdx + 1);  // 结束行（+1表示占1行高度）

            // 5. 插入图片
            drawing.createPicture(anchor, pictureIdx);
        } catch (IOException e) {
            System.err.println("图片插入失败: " + e.getMessage());
        }
    }


    // 生成动态表头
    private List<List<String>> genHeader(Chain chain,List<String> dynamicHeaders) {
        //按照列排序的方式处理
        List<List<String>> headTitles = Lists.newArrayList();

        String headTitle = "【" + chain.getName() + "】" + "预留成功名单";
//        String headPicUrl = getHeadPicUrl(chain.getPics());
        String headPicUrl = "";
        headTitles.add(Lists.newArrayList(headTitle, headPicUrl, "接龙号")); //每个代表1列
        headTitles.add(Lists.newArrayList(headTitle, headPicUrl, "微信名"));
        headTitles.add(Lists.newArrayList(headTitle, headPicUrl, "淘***旺旺id"));
        dynamicHeaders.forEach(dynamicHeader -> {
            headTitles.add(Lists.newArrayList(headTitle ,headPicUrl, dynamicHeader));
        });
        headTitles.add(Lists.newArrayList(headTitle, headPicUrl, "是否超限"));
        headTitles.add(Lists.newArrayList(headTitle, headPicUrl, "淘宝账号(旺旺id)"));
        headTitles.add(Lists.newArrayList(headTitle, headPicUrl, "旺店通加密id"));
        headTitles.add(Lists.newArrayList(headTitle, headPicUrl, "商家编码"));
        headTitles.add(Lists.newArrayList(headTitle, headPicUrl, "VIP等级"));
        return headTitles;
    }


    private String getHeadPicUrl(String relativeUrl) {
        return envUtil.isProd()?"https://chenfan-chain.oss-cn-hangzhou.aliyuncs.com/" + relativeUrl + "?x-oss-process=image/resize,p_20" : "http://10.228.86.207:8911/file/" + relativeUrl;
    }





}
